package com.example.financeapi.service.impl;

import com.example.financeapi.entity.FMyPurchase;
import com.example.financeapi.mapper.FMyPurchaseMapper;
import com.example.financeapi.service.FMyPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 我的申购表(FMyPurchase)表服务实现类
 * @author Alvin
 * @since 2020-03-31 12:04:32
 */
@Service
public class FMyPurchaseServiceImpl implements FMyPurchaseService {
    @Autowired
    private FMyPurchaseMapper fMyPurchaseMapper;

    /**
     * 我的打新记录列表
     * @param map
     * @return
     */
    @Override
    public List<FMyPurchase> getMyPurchaseList(Map<String,Object> map) {
        return fMyPurchaseMapper.getMyPurchaseList(map);
    }

    /**
     * 申购或中签列表
     * @param paramMap
     * @return
     */
    @Override
    public List<FMyPurchase> getPurchOrWinList(Map<String, Object> paramMap) {
        String flag = (String) paramMap.get("flag");
        if("0".equals(flag)){
            paramMap.put("flag","");
        }
        return fMyPurchaseMapper.getPurchOrWinList(paramMap);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FMyPurchase queryById(Integer id) {
        return this.fMyPurchaseMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param fMyPurchase 实例对象
     * @return 实例对象
     */
    @Override
    public FMyPurchase insert(FMyPurchase fMyPurchase) {
        this.fMyPurchaseMapper.insert(fMyPurchase);
        return fMyPurchase;
    }

    /**
     * 修改数据
     *
     * @param fMyPurchase 实例对象
     * @return 实例对象
     */
    @Override
    public FMyPurchase update(FMyPurchase fMyPurchase) {
        this.fMyPurchaseMapper.update(fMyPurchase);
        return this.queryById(fMyPurchase.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.fMyPurchaseMapper.deleteById(id) > 0;
    }

}